package com.qyer.flume.schedule;

import com.qyer.flume.sink.CronRollingFileSink;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * User: Z J Wu Date: 2015/05/14 Time: 20:11 Package: com.qyer.flume.schedule
 */
public class CronScheduleJob implements Job {
  private static final Logger LOGGER = LoggerFactory.getLogger(CronScheduleJob.class);

  @Override public void execute(JobExecutionContext context) throws JobExecutionException {
	LOGGER.debug("CronScheduleJob   execute  start --------------");
    // 在Trigger的Job中设置rotate标识
    JobKey key = context.getJobDetail().getKey();
    JobDataMap dataMap = context.getJobDetail().getJobDataMap();
    Object sinkObj = dataMap.get(key.getName());
    if (sinkObj == null) {
      LOGGER.warn("Sink passed to cron job is null, cannot set rotating flag.");
      return;
    }
    CronRollingFileSink sink = (CronRollingFileSink) sinkObj;
    sink.setShouldRotate(true);
    LOGGER.debug("CronScheduleJob   execute  end --------------");
  }
}
